package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzFormFieldChangeLog;
import com.zzedu.dto.ZzFormFieldChangeLogDTO;
import com.zzedu.service.IZzFormFieldChangeLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字段变更日志Controller
 * 
 * @author Mr.Wang
 * @date 2025-05-31
 */
@RestController
@RequestMapping("/zzedu/fieldLog")
public class ZzFormFieldChangeLogController extends BaseController
{
    @Autowired
    private IZzFormFieldChangeLogService zzFormFieldChangeLogService;

    /**
     * 查询字段变更日志列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzFormFieldChangeLogDTO zzFormFieldChangeLog)
    {
        return getDataTable(zzFormFieldChangeLogService.page(zzFormFieldChangeLog.getPageDTO(),zzFormFieldChangeLogService.buildQuery(zzFormFieldChangeLog)));
    }

    /**
     * 导出字段变更日志列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:export')")
    @Log(title = "字段变更日志", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzFormFieldChangeLogDTO zzFormFieldChangeLog)
    {
        List<ZzFormFieldChangeLog> list = zzFormFieldChangeLogService.list(zzFormFieldChangeLogService.buildQuery(zzFormFieldChangeLog));
        ExcelUtil<ZzFormFieldChangeLog> util = new ExcelUtil<ZzFormFieldChangeLog>(ZzFormFieldChangeLog.class);
        util.exportExcel(ServletUtils.getResponse(),list, "字段变更日志数据");
    }




    /**
     * 新增保存字段变更日志
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:add')")
    @Log(title = "字段变更日志", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzFormFieldChangeLog zzFormFieldChangeLog)
    {
        return toAjax(zzFormFieldChangeLogService.save(zzFormFieldChangeLog));
    }



    /**
     * 获取字段变更日志详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zzFormFieldChangeLogService.getById(id));
    }


    /**
     * 修改保存字段变更日志
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:edit')")
    @Log(title = "字段变更日志", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzFormFieldChangeLog zzFormFieldChangeLog)
    {
        return toAjax(zzFormFieldChangeLogService.updateById(zzFormFieldChangeLog));
    }

    /**
     * 删除字段变更日志
     */
    @PreAuthorize("@permission.hasAnyPermissions('zzedu:fieldLog:remove')")
    @Log(title = "字段变更日志", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(zzFormFieldChangeLogService.removeBatchByIds(ids));
    }
}
